﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;

namespace Beijing2008
{
	public partial class MainWindow
	{
        private System.Timers.Timer timerMain;
 

		public MainWindow()
		{
			this.InitializeComponent();
			
			// 在此点之下插入创建对象所需的代码。
            this.Closed += new EventHandler(MainWindow_Closed);
            this.timerMain = new System.Timers.Timer(2000);
            this.timerMain.Elapsed += new System.Timers.ElapsedEventHandler(timerMain_Elapsed);
            this.timerMain.Enabled = true;
            this.timerMain.Start();
            udd = new UpdateDaysDelegate(UpdateDaysMethd);
            foreach(UIElement ui in this.gridItems.Children)
            {
                ui.MouseEnter+= new System.Windows.Input.MouseEventHandler(Image_MouseEnter);
            }
		}

        void Image_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            try
            {
                
                System.Windows.Controls.Image img = (System.Windows.Controls.Image)e.Source;
                System.Xml.XmlAttribute xa = (System.Xml.XmlAttribute)img.Tag;
                this.txtDescription.Text = "       " + xa.Value;
            }
            catch
            {

            }
        }

        void MainWindow_Closed(object sender, EventArgs e)
        {
            this.timerMain.Elapsed+=new System.Timers.ElapsedEventHandler(timerMain_Elapsed);
        }
        public delegate void UpdateDaysDelegate(string days);
        UpdateDaysDelegate udd;
        public void UpdateDaysMethd(string days)
        {
            this.txtDays.Text = days;
        }
        void timerMain_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            System.DateTime dt = new DateTime(2008, 8, 8);
            System.DateTime dtNow = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, System.DateTime.Now.Day);
            System.TimeSpan ts = dt - dtNow;
            App.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background,this.udd,ts.Days.ToString());
        }

	}
}